<?php
// +----------------------------------------------------------------------
// | Qbt CMS Plugin
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2018 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 黄老邪 <develop02@qbt8.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_custom_model\controller; //Demo插件英文名，改成你的插件英文就行了

use cmf\controller\PluginAdminBaseController;
use think\Db;
class AdminIndexController extends PluginAdminBaseController
{

    public function _initialize()
    {
        $adminId = cmf_get_current_admin_id();//获取后台管理员id，可判断是否登录
        if (!empty($adminId)) {
            $this->assign("admin_id", $adminId);
        } else {
            $this->error('未登录');
        }
    }

    /**
     * 千佰特自定义模型管理
     * @adminMenu(
     *     'name'   => '模型管理',
     *     'parent' => 'admin/Plugin/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '模型管理',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        //取出所有模型
        $model_list = Db::name('model')->order("model_id asc")->paginate(10);
        $page = $model_list->render();
        $this->assign('model_list', $model_list);
        $this->assign('page', $page);
        //删除backup下面文件
        /*$path = WEB_ROOT . 'plugins/' .'qbt_custom_model/data/backup/';
        if(file_exists($path.'model.sql')){
            @unlink($path.'model.sql');
        }
        if(file_exists($path.'model.zip')){
            @unlink($path.'model.zip');
        }*/
        return $this->fetch('/admin_index');
    }

}
